#!/bin/env ruby
# encoding: utf-8
require_relative '../spec/spec_helper'
require_relative '../spec/commons/user_auth'
require_relative '../spec/commons/check_page'

describe 'Profile info tab on profile page' do 	
	before {

	}
  context "when logged in as user" do
    it "then he can work with system"  do                  
      sign_in('mutual_1_koun@list.ru', '11qqAA**')
      check_userprofile_page()
    end
  end

  context 'when  submit First Name' do 
  	it 'then it can not be empty' do
      goto 'https://mutualforce.7bits.it/userHomePage.html'
      a(class: "b-button b-user-menu__link js-b-user-menu__login-link").click
      a(class: "b-user-menu__list-link", href: "userProfile.html").click
      a(class: "b-tabs__list-item-link", href: "#tabs-profile-info").click
                 
  		text_field(class: "b-form__input_text js-bad-form-input", name: "firstName", id:"firstName").clear
  		button(class: "b-button b-form__input_submit", value: "Submit").click
  		span(class: "b-form__error js-bad-form-field", id: "firstName.errors", text: 'Please enter info here.').wait_until_present(5)  		
  	end  	
  end

  context 'when sumit First Name' do
    it 'then it can contain less than or equal to 50 characters' do
      browser.refresh

      text_field(class: "b-form__input_text js-bad-form-input", name: "firstName", id:"firstName").clear
      text_field(class: "b-form__input_text js-bad-form-input", name: "firstName", id:"firstName").set str(55)
      button(class: "b-button b-form__input_submit", value: "Submit").click
      span(class: "b-form__error js-bad-form-field", id: "firstName.errors", text: 'Can contain less than or equal to 50 characters')
      .wait_until_present(5)           
    end
  end

  context 'when submit Last Name' do 
    it 'then it can not be empty' do
      browser.refresh
                 
      text_field(class: "b-form__input_text js-bad-form-input", name: "lastName", id:"lastName").clear
      button(class: "b-button b-form__input_submit", value: "Submit").click
      span(class: "b-form__error js-bad-form-field", id: "lastName.errors", text: 'Please enter info here.').wait_until_present(5)     
    end
  end

  context 'when submit Last Name' do
    it 'then it can contain less than or equal to 50 characters' do
      browser.refresh

      text_field(class: "b-form__input_text js-bad-form-input", name: "lastName", id:"lastName").clear
      text_field(class: "b-form__input_text js-bad-form-input", name: "lastName", id:"lastName").set str(55)
      button(class: "b-button b-form__input_submit", value: "Submit").click
      span(class: "b-form__error js-bad-form-field", id: "lastName.errors", text: 'Can contain less than or equal to 50 characters')
      .wait_until_present(5)           
    end
  end

  context 'when submit address' do
    it 'then it can not be empty' do
      browser.refresh
      text_field(class: "b-form__input_text js-bad-form-input", name: "postAddressForm.street", id:"postAddressForm.street").clear
      button(class: "b-button b-form__input_submit", value: "Submit").click
      span(class: "b-form__error js-bad-form-field", id: "postAddressForm.street.errors", text: "Please enter info here.")
      .wait_until_present(5)
    end 
  end

  context 'when submit address' do
    it 'then it can contain less than or equal to 60 characters' do
      browser.refresh

      text_field(class: "b-form__input_text js-bad-form-input", name: "postAddressForm.street", id:"postAddressForm.street").clear
      text_field(class: "b-form__input_text js-bad-form-input", name: "postAddressForm.street", id:"postAddressForm.street").set str(65)
      button(class: "b-button b-form__input_submit", value: "Submit").click    
      span(class: "b-form__error js-bad-form-field", id: "postAddressForm.street.errors", text: 'Should be less or equal to 60 characters')
      .wait_until_present(5)           
    end
  end

  context 'when submit city' do
    it 'then it can not be empty' do
      browser.refresh

      text_field(class: "b-form__input_text js-bad-form-input", name: "postAddressForm.city", id:"postAddressForm.city").clear
      button(class: "b-button b-form__input_submit", value: "Submit").click
      span(class: "b-form__error js-bad-form-field", id: "postAddressForm.city.errors", text: "Please enter info here.")
      .wait_until_present(5)
    end 
  end

  context 'when submit city' do
    it 'then it can contain less than or equal to 50 characters' do
      browser.refresh

      text_field(class: "b-form__input_text js-bad-form-input", name: "postAddressForm.city", id: "postAddressForm.city").clear
      text_field(class: "b-form__input_text js-bad-form-input", name: "postAddressForm.city", id: "postAddressForm.city").set str(55)
      button(class: "b-button b-form__input_submit", value: "Submit").click    
      span(class: "b-form__error js-bad-form-field", id: "postAddressForm.city.errors", text: 'Should be less or equal to 50 characters')
      .wait_until_present(5)           
    end
  end
          
  context 'when submit zip' do
    it 'then it can not be empty' do
      browser.refresh
      
      text_field(id: "postAddressForm.zip", class: "b-form__input_number js-bad-form-input", name: "postAddressForm.zip").wait_until_present(6)
      text_field(id: "postAddressForm.zip", class: "b-form__input_number js-bad-form-input", name: "postAddressForm.zip").clear
      button(class: "b-button b-form__input_submit", value: "Submit").click
      span(class: "b-form__error js-bad-form-field", id: "postAddressForm.zip.errors", text: "Please enter info here.").wait_until_present(5)
    end 
  end

  context 'when submit zip' do
    it 'then it can contain less than or equal to 6 characters' do
      browser.refresh

      text_field(class: "b-form__input_number js-bad-form-input", name: "postAddressForm.zip", id: "postAddressForm.zip").wait_until_present(6)
      text_field(class: "b-form__input_number js-bad-form-input", name: "postAddressForm.zip", id: "postAddressForm.zip").clear
      text_field(class: "b-form__input_number js-bad-form-input", name: "postAddressForm.zip", id: "postAddressForm.zip").set "1234567"
      button(class: "b-button b-form__input_submit", value: "Submit").click    
      span(class: "b-form__error js-bad-form-field", id: "postAddressForm.zip.errors", text: 'Should be 6 characters')
      .wait_until_present(5)           
    end
  end

  context "when logged out" do
    it "then he can't work with system"  do
      user_logout()
    end
  end

end
